package com.sparrow.mvc.ui;

import com.sparrow.utils.StringUtil;

@SuppressWarnings("serial")
public class JHyperLink extends JWebBodyControl {

	private String href;
	private String target;

	@Override
	public String setTagNameAndGetTagAttributes() {
		super.setTagName("a");
		StringBuffer str = new StringBuffer("");
		str.append(this.getHref());
		str.append(this.getTarget());
		return str.toString();
	}

	public String getHref() {
		Object requestHref = this.pageContext.getRequest().getAttribute(
				this.getId() + ".href");
		if (requestHref != null) {
			return String.format(" href=\"%1$s\"", requestHref);
		} else {
			if (this.href != null && this.href.trim() != "") {
				return String.format(" href=\"%1$s\"", this.href);
			} else {
				return "";
			}
		}
	}

	public void setHref(String href) {
		this.href = href;
	}

	public String getTarget() {
		Object requestTarget = this.pageContext.getRequest().getAttribute(
				this.getId() + ".target");
		if (requestTarget != null) {
			return String.format(" href=\"%1$s\"", requestTarget);
		} else {
			if (!StringUtil.isNullOrEmpty(this.target)) {
				return String.format(" target=\"%1$s\" ", this.href);
			} else {
				return "";
			}
		}
	}

	public void setTarget(String target) {
		this.target = target;
	}

}
